package org.huanletao.ssm.service;

import org.huanletao.ssm.mapper.MenuMapper;
import org.huanletao.ssm.model.SysMenu;
import org.huanletao.ssm.model.User;
import org.huanletao.ssm.service.base.BaseService;
import org.huanletao.ssm.util.TreeNode;
import org.huanletao.ssm.util.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * <p>
 * </p>
 * package: org.huanletao.ssm.service
 * description:
 * className: SysMenuService
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/8/28 17:26
 * since: 1.0.0
 */
@Service
public class SysMenuService extends BaseService<SysMenu> {

    @Autowired
    private MenuMapper menuMapper;
    /**
     * 查询当前用户菜单；
     *
     * @param currentUser
     * @return
     */
    public List<SysMenu> selectCurrentUserMenus(User currentUser) {
        List<SysMenu> sysMenus = menuMapper.selectMenusByRoleId(currentUser.getRole().getRoleId());
        return TreeUtils.buildTree(sysMenus);
    }

    @Override
    protected Mapper<SysMenu> getMapper() {
        return menuMapper;
    }
}
